package org.itboys.trade.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.itboys.admin.constant.AdminSessionConstant;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mongodb.utils.page.Page;
import org.itboys.mongodb.utils.query.QueryParamUtils;
import org.itboys.trade.dto.OrderDto;
import org.itboys.trade.dto.WXCommentListDto;
import org.itboys.trade.service.CommentService;
import org.itboys.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 订单
 * @author weisky
 *
 */
@RestController 
@RequestMapping("/comment") 
public class CommentController extends BaseController{

	@Autowired
	private CommentService commentService;
	
	
	/**
	 * 跳到页面 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/toListVM")
	public ModelAndView toListVM(HttpServletRequest request, HttpServletResponse response) {
		return new ModelAndView("/comment/list");
	}
	@RequestMapping("/list")
	public void list(
			HttpServletRequest request, HttpServletResponse response){
		Map<String, Object> sqlMap = QueryParamUtils.builderQueryMap(request);// 组装查询参数
		Long sellerId=(Long)request.getSession().getAttribute(AdminSessionConstant.SHOP_ID);
		Long centerId=(Long)request.getSession().getAttribute(AdminSessionConstant.CENTER_ID);
		if (null!=sellerId) {
			sqlMap.put("shopId", sellerId);
		}
		if (null!=centerId) {
			sqlMap.put("centerId",centerId);
		}
		Page<WXCommentListDto>result=commentService.getWebCommentListDtos(sqlMap);
		JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),
				response);
	}
	@RequestMapping("/delete")
	public void delete(@RequestParam Long id,HttpServletRequest request, HttpServletResponse response) {
		commentService.update(id, "deleted", true);
		AjaxUtils.renderText(response, "success");
	}
}
	
	